import axios from "@/libs/api.request";

export const getTableData = () => {
  return axios.request({
    url: "get_table_data",
    method: "get"
  });
};

export const getDragList = () => {
  return axios.request({
    url: "get_drag_list",
    method: "get"
  });
};

export const errorReq = () => {
  return axios.request({
    url: "error_url",
    method: "post"
  });
};

export const saveErrorLogger = info => {
  return axios.request({
    url: "save_error_logger",
    data: info,
    method: "post"
  });
};

// 获取用户数据
export const getUserList2 = () => {
  return axios.request({ url: "get_user_list", method: "get" });
};

// 获取角色数据
export const getRoleList = () => {
  return axios.request({ url: "get_role_list", method: "get" });
};

// 获取菜单数据
export const getAllMenus= token => {
    return axios.request({ url: "api/admin/getmenu", method: "post" });
};
// 获取菜单数据
// export const getAllMenus = token => {
//     return axios.request({ url: "get_all_menus", method: "get" });
// };


// 获取用户数据
export const getUserList = (data1) => {
    let data = data1
    return axios.request({ url: "api/admin/getUserList", data,method: "post" });
};



// 获取角色数据  
export const getGroupList = (data1) => {
     let data = data1 || {"page":1,"length":1000,"keywords":""}

    console.log('group_data:',data);
    return axios.request({ url: "api/admin/getGroupList",data, method: "post" });
};

// 获取所有菜单列表包括菜单和按钮
export const getMenuList = ({menu_type}) => {
    const data = {
        "menu_type": menu_type
    }
    return axios.request({ url: "api/admin/getMenuList", data, method: "post" });
};

// 排序
export const setSort = ({ id,val }) => {
    const data = {
        "id": id,
        "sort":val
    }
    return axios.request({ url: "api/admin/setSort", data, method: "post" });
};

// 修改menu
export const editMenu = (data1) => {
    let data = data1
    return axios.request({ url: "api/admin/editMenu", data, method: "post" });
};

// add menu
export const addMenu = (addData1) => {
    let data = addData1
    console.log('addData:::::', data);
    return axios.request({ url: "api/admin/addMenu", data, method: "post" });
};

// add menu
export const delMenu = (delData) => {
    let data = delData
    console.log('delData:::::', data);
    return axios.request({ url: "api/admin/delMenu", data, method: "post" });
};

// del user
export const delUser = (delData) => {
    let data = delData
    console.log('delUser:::::', data);
    return axios.request({ url: "api/admin/delUser", data, method: "post" });
};

// edit user status
export const editStatus = (userData) => {
    let data = userData
    console.log('editUserStatus:::::', data);
    return axios.request({ url: "api/admin/editUserStatus", data, method: "post" });
};


// addUser 添加用户
export const addUser = (userData) => {
    let data=userData;
    return axios.request({ url: "api/admin/addUser", data,method: "post" });
};

// editUser 修改用户
export const editUser = (userData) => {
    let data=userData;
    return axios.request({ url: "api/admin/editUser", data,method: "post" });
};

// 删除用户组
export const delGroup = (userData) => {
    let data=userData;
    return axios.request({ url: "api/admin/delGroup", data,method: "post" });
};

//addGroup
export const addGroup = (userData) => {
    let data=userData;
    return axios.request({ url: "api/admin/addGroup", data,method: "post" });
};

export const editGroup = (userData) => {
    let data=userData;
    return axios.request({ url: "api/admin/editGroup", data,method: "post" });
};


//getPermissionsByRoleId
export const getPermissionsByRole = (userData) => {
    let data=userData;
    return axios.request({ url: "api/admin/getPermissionsByRole", data,method: "post" });
};

// 获取所有用户
export const getAllUsers = (userData) => {
    let data=userData;
    return axios.request({ url: "api/admin/getAllUsers",method: "post" });
};

//
// 获取所有用户
export const getGroupUsers = (userData) => {
    let data=userData;
    console.log('groupData:',data);
    return axios.request({ url: "api/admin/getGroupUsers",data,method: "post" });
};

//保存角色对应的用户数据
export const saveGroupUsers = (userData) => {
    let data=userData;
    console.log('saveGroupUsersdata:',data);
    return axios.request({ url: "api/admin/saveGroupUsers",data,method: "post" });
};

//获取单个用户信息
export const getUserInfo = (userData) => {
    return axios.request({ url: "api/admin/getUserInfo",method: "post" });
};


//保存角色对应的用户数据
export const editUserInfo = (userData) => {
    let data=userData;
    console.log('editUserInfo:',data);
    return axios.request({ url: "api/admin/editUserInfo",data,method: "post" });
};